
var orderinfo;  //订单详情
var ordertype;
var status;


apiready = function(){
    
    orderinfo=api.pageParam.order;console.log(JSON.stringify(orderinfo));
    ordertype=orderinfo.type;
    status=orderinfo.status;
    
    if(status=='待支付'||status=='待发货'){
       $api.attr($api.byId('statusimg'), 'src', 'images/order/st1.jpg');
    }else if(status=='待收货'||status=='已发货'){
       $api.attr($api.byId('statusimg'), 'src', 'images/order/st2.png');
    }
    
    if(status=='交易完成'){
      $api.attr($api.byId('statusimg'), 'src', 'images/order/st3.png');
      $api.removeCls($api.byId('commentbut'), 'am-disabled');
    }
    

    $api.text($api.byId('orderstatus'), orderinfo.status);
    $api.text($api.byId('receiver'), orderinfo.receiver);
    $api.text($api.byId('mobile'), orderinfo.mobile);
    
    if(ordertype=='SP'){
      $api.text($api.byId('address'), orderinfo.address);
      $api.text($api.byId('freight'), "￥"+orderinfo.freight?((orderinfo.freight).toFixed(2)):0);
      $api.text($api.byId('proTotal'), "￥"+orderinfo.proTotal.toFixed(2));
    }else if(ordertype=='LY'){
      $api.css($api.byId('mapicon'),'display:none');
      $api.text($api.byId('receiverdiv'), '联系人');
      $api.css($api.byId('addressdiv'),'display:none');
      $api.css($api.byId('freightdiv'),'display:none');
      $api.css($api.byId('proTotaldiv'),'display:none');
      
    }else if(ordertype=='WY'){
       $api.css($api.byId('mapicon'),'display:none');
       $api.css($api.byId('shouhuodiv'),'display:none');
       $api.css($api.byId('shdz'),'display:none');
       $api.text($api.byId('address'), orderinfo.address);
       $api.css($api.byId('freightdiv'),'display:none');
       $api.css($api.byId('proTotaldiv'),'display:none');
       
    }else if(ordertype=='OT'){

    }

    $api.text($api.byId('total'), "￥"+orderinfo.total.toFixed(2));
    $api.text($api.byId('orderNo'), orderinfo.orderNo);
    $api.text($api.byId('createTime'), orderinfo.createTime);
    $api.text($api.byId('payType'), orderinfo.payType);
    $api.text($api.byId('payTime'), orderinfo.payTime||'未支付');
    
    
    var dataHtml='';
    
    if(ordertype=='SP'){
        var merName='';   //商家名称
	    var prolist=orderinfo.item;
	    var prolist2=orderinfo.item;
	    for (var i in prolist) {
			
			if (prolist[i].merName != merName) {
			
				dataHtml +='<div class="am-u-sm-12" style="background: #FFFFFF;padding:8px 10px">';
				dataHtml +='<span>'+prolist[i].merName+'</span>';
				dataHtml +='<span style="float: right">'+prolist[i].status+'</span>';
				dataHtml +='</div>';
				
				for (var j in prolist2) {
				
					if (prolist[i].merName == prolist2[j].merName) {
					    dataHtml +='<div class="am-u-sm-12" style="background: #FEEBDC">';
					    dataHtml +='<div class="am-u-sm-12" style="padding:0px">';
					    dataHtml +='<div  style="border-bottom:1px solid #eaedf1;padding:0px;">';
					    dataHtml +='<table  border="0" width="100%" style="margin:8px 0px;table-layout:fixed;">';
						    dataHtml +='<tr>';
							    dataHtml +='<td rowspan="3" valign="middle" style="width:70px;">';
							    dataHtml +='<img src="'+serviceUrl+'/files/'+(prolist2[j].proDefImg||0)+'"  style="width:65px;height:70px;"/>';
							    dataHtml +='</td>';
							    dataHtml +='<td rowspan="2" width="60%"  style="word-break:break-all;font-size:14px"  valign="top">';
							    dataHtml +=prolist2[j].proName;
							    dataHtml +='</td>';
							    dataHtml +='<td valign="top" align="right" >';
							    dataHtml +='￥'+prolist2[j].price.toFixed(2);
							    dataHtml +='</td>';
						    dataHtml +='</tr>';
					        dataHtml +='<tr></tr>';
					        dataHtml +='<tr>';
							    dataHtml +='<td></td>';
							    dataHtml +='<td  valign="bottom" align="right" style="font-size:10px;max-width:110px;">';
							    dataHtml +='X'+prolist2[j].num;
							    dataHtml +='</td>';
					        dataHtml +='</tr>';
					      dataHtml +='</table>';
					    dataHtml +='</div>';
					    dataHtml +='</div>';
					    dataHtml +='</div>';

					}
				}
				
				merName = prolist[i].merName;
				
				if(prolist[i].status!='待发货'){
			
					dataHtml +='<div class="am-u-sm-12">';
					dataHtml +='<div>发货时间：'+prolist[i].sendTime+'</div>';
					dataHtml +='<div>发货地址：'+prolist[i].sendAddress+'</div>';
					dataHtml +='<div>配送物流：'+prolist[i].sendWay+'</div>';
					dataHtml +='<div>物流单号：'+prolist[i].logisticsNo+'</div>';
					dataHtml +='</div>';
				}
			}
		}
	
	}else if(ordertype=='LY'){
	    dataHtml +='<div class="am-u-sm-12" style="background: #FFFFFF;padding:8px 10px">';
		dataHtml +='<span>'+orderinfo.merName||""+'</span>';
		dataHtml +='</div>';
		
		dataHtml +='<div class="am-u-sm-12" style="background: #FEEBDC">';
	    dataHtml +='<div class="am-u-sm-12" style="padding:0px">';
	    dataHtml +='<div  style="border-bottom:1px solid #eaedf1;padding:0px;">';
	    dataHtml +='<table  border="0" width="100%" style="margin:8px 0px;table-layout:fixed;">';
		    dataHtml +='<tr>';
			    dataHtml +='<td rowspan="3" valign="middle" style="width:70px;">';
			    dataHtml +='<img src="'+serviceUrl+orderinfo.proDefImg+'"  style="width:65px;height:70px;"/>';
			    dataHtml +='</td>';
			    dataHtml +='<td rowspan="2" colspan="2" width="60%"  style="word-break:break-all;font-size:14px"  valign="top">';
			    dataHtml +=orderinfo.tourname;
			    dataHtml +='</td>';
			   
		    dataHtml +='</tr>';
	        dataHtml +='<tr></tr>';
	        dataHtml +='<tr>';
			    dataHtml +='<td  valign="bottom" colspan="2" align="right" style="font-size:10px;max-width:110px;">';
			    dataHtml +='成人数量：'+orderinfo.crnum+',￥'+orderinfo.crtotal+';儿童数量：'+orderinfo.etnum+',￥'+orderinfo.ertatol||'0';
			    dataHtml +='</td>';
	        dataHtml +='</tr>';
	      dataHtml +='</table>';
	    dataHtml +='</div>';
	    dataHtml +='</div>';
	    dataHtml +='</div>';
	
	}else if(ordertype=='WY'){
	    
	    var yearmonth = "";
    	var result = orderinfo.item;
    	var resultT = orderinfo.item;
    	var dataHtml="";
    	for (var i in result) {
			
				if (result[i].yearmonth != yearmonth) {
				
					dataHtml += '<div class="am-u-sm-12" style="background:#efefef;border-radius:5px;padding:2px;color:red;">';
					dataHtml += result[i].yearmonth;
					dataHtml += '</div>';
					
					for (var j in resultT) {
					
						if (result[i].yearmonth == resultT[j].yearmonth) {
						
							dataHtml += '<div class="am-u-sm-12" style="padding:8px;">';
							
							dataHtml += '<div class="am-u-sm-6" style="padding:0px;">';
							dataHtml += result[j].name;
							dataHtml += '</div>';
							
							dataHtml += '<div class="am-u-sm-6" style="padding:0px;">';
							dataHtml += '￥'+result[j].cost;
							dataHtml += '</div>';
							
							dataHtml += '</div>';
						}
					}
					
					yearmonth = result[i].yearmonth;
				}
			}
	}
	
	$api.byId("orderitem").innerHTML = dataHtml;

};



//删除订单
function delorder(){
   
  //  alert(JSON.stringify(orderinfo));
    api.confirm({title: '提示',msg:'确定删除吗?',buttons:['确定','取消']},function(ret,err){
			if(ret.buttonIndex == 1){
				
				do_ajax('/app/member/delMyOrder','post',{'orderId':orderinfo._id,'ordertype':ordertype},function(ret,err){
				    api.hideProgress();
				    if(ret.resultCode=='0'){
				        //发送订单改变事件
				        api.sendEvent({
						    name: 'changeOrder',
						});
						
				        toast('删除成功');
				        api.closeWin();
				        
				    }else{
				        toast('操作失败');   
				    }
				
				});
				
				
			}
	});

};

//去评价
function addcomment(){
     openWin('commentpro',{'order':orderinfo});
};








